﻿// 主页面

#include "HomePage.h"

void drawHomePage(float width, float height)
{
    float ascale_x = width / 2560.0;  // X 方向缩放因子
    float ascale_y = ascale_x; // Y 方向缩放因子

    float x0 = 17 * ascale_x;
    float y0 = 11 * ascale_y;
    // 背景
    setlinecolor(BLACK);
    setfillcolor(EGEARGB(255, 105, 103, 101));
    ege_fillroundrect(x0, y0, 2520 * ascale_x, 1562 * ascale_y, 689 * ascale_x, 0, 0, 0);
    setlinewidth(3 * ascale_x);
    setlinecolor(BLACK);
    ege_roundrect(694 * ascale_x, 0 * ascale_y, 1287 * ascale_x, 1024 * ascale_y, 0, 0, 10 * ascale_x, 10 * ascale_x);
    ege_line(1336 * ascale_x, 1024 * ascale_y, 1336 * ascale_x, height);
    // 标签
    setfillcolor(EGEARGB(255, 36, 34, 30));
    setlinecolor(EGEARGB(255, 0, 0, 0));
    ege_roundrect(951 * ascale_x, 40 * ascale_y, 190 * ascale_x, 75 * ascale_y, 10 * ascale_x);
    ege_fillroundrect(951 * ascale_x, 40 * ascale_y, 190 * ascale_x, 75 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 20, 19, 17));
    ege_roundrect(962 * ascale_x, 50 * ascale_y, 168 * ascale_x, 55 * ascale_y, 10 * ascale_x);

    ege_fillroundrect(962 * ascale_x, 50 * ascale_y, 168 * ascale_x, 55 * ascale_y, 10 * ascale_x);
    setbkmode(TRANSPARENT);
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    setcolor(WHITE);
    setfont((int)(50 * ascale_x), 0, "Arial Narrow");
    ege_outtextxy(1045 * ascale_x, 55 * ascale_y, "N172SP");

    // 标签右边的
    setcolor(BLACK);
    ege_roundrect(1458 * ascale_x, 40 * ascale_y, 327 * ascale_x, 77 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 22, 20, 19));
    ege_fillroundrect(1458 * ascale_x, 40 * ascale_y, 327 * ascale_x, 77 * ascale_y, 10 * ascale_x);
    ege_roundrect(1468 * ascale_x, 50 * ascale_y, 307 * ascale_x, 55 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 18, 17, 15));
    ege_fillroundrect(1468 * ascale_x, 50 * ascale_y, 307 * ascale_x, 55 * ascale_y, 10 * ascale_x);
    setbkmode(TRANSPARENT);
    setfont((int)(30 * ascale_x), 0, "Arial Narrow");
    //        setcolor(EGEARGB(255, 36, 31, 27));
    setcolor(EGEARGB(255, 191, 175, 102));
    settextjustify(LEFT_TEXT, TOP_TEXT);
    ege_outtextxy(1475 * ascale_x, 52 * ascale_y, "L FUEL R");
    setcolor(EGEARGB(255, 176, 43, 31));
    ege_outtextxy(1475 * ascale_x, 78 * ascale_y, "QIL PRESS");
    setcolor(EGEARGB(255, 128, 117, 58));
    ege_outtextxy(1605 * ascale_x, 78 * ascale_y, "L VAC R");
    setcolor(EGEARGB(255, 176, 43, 31));
    ege_outtextxy(1701 * ascale_x, 78 * ascale_y, "VOLTS");

    // NAV GPS 如果可以点击更好
    setlinecolor(EGEARGB(255, 0, 0, 0));
    ege_roundrect(2110 * ascale_x, 40 * ascale_y, 155 * ascale_x, 77 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 22, 20, 19));
    ege_fillroundrect(2110 * ascale_x, 40 * ascale_y, 155 * ascale_x, 77 * ascale_y, 10 * ascale_x);
    ege_roundrect(2120 * ascale_x, 50 * ascale_y, 135 * ascale_x, 57 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 18, 17, 15));
    ege_fillroundrect(2120 * ascale_x, 50 * ascale_y, 135 * ascale_x, 57 * ascale_y, 10 * ascale_x);
    setcolor(EGEARGB(255, 184, 175, 80));
    ege_outtextxy(2133 * ascale_x, 52 * ascale_y, "NAV");
    setcolor(EGEARGB(255, 35, 175, 134));
    ege_outtextxy(2133 * ascale_x, 80 * ascale_y, "GPS");

    setlinecolor(EGEARGB(255, 255, 255, 255));
    ege_roundrect(2197 * ascale_x, 55 * ascale_y, 47 * ascale_x, 47 * ascale_y, 10 * ascale_x);
    setfillcolor(EGEARGB(255, 21, 21, 22));
    ege_fillroundrect(2197 * ascale_x, 55 * ascale_y, 47 * ascale_x, 47 * ascale_y, 10 * ascale_x);
    setcolor(EGEARGB(255, 255, 255, 255));
    setfont((int)(23 * ascale_x), 0, "Arial Narrow");
    ege_outtextxy(2205 * ascale_x, 60 * ascale_y, "NAV");
    ege_outtextxy(2205 * ascale_x, 78 * ascale_y, "GPS");

    // 左下角的板子
    setlinecolor(EGEARGB(255, 0, 0, 0));
    ege_roundrect(86 * ascale_x, 1300 * ascale_y, 1047 * ascale_x, 191 * ascale_y, 10 * ascale_x);
    //setfillcolor(WHITE);
    drawPanle(86 * ascale_x, 1300 * ascale_y, 191 * ascale_y);
    //ege_fillroundrect(86 * ascale_x, 1300 * ascale_y, 1047 * ascale_x, 191 * ascale_y, 10 * ascale_x);

    // 一些文字的显示
    setbkmode(TRANSPARENT);
    setfont((int)(30 * ascale_x), 0, "Arial Narrow");
    setcolor(EGEARGB(255, 200, 200, 200));
    ege_outtextxy(860 * ascale_x, 1079 * ascale_y, "WARNING");
    setfont((int)(25 * ascale_x), 0, "Arial Narrow");
    settextjustify(LEFT_TEXT, TOP_TEXT);
    ege_outtextxy(732 * ascale_x, 1120 * ascale_y, "ASSUME THAT SEAT IS LOCKED IN POSITION");
    ege_outtextxy(732 * ascale_x, 1140 * ascale_y, "PRIOR TO TAXI. TAKE-OFF, AND LANDING.");
    ege_outtextxy(732 * ascale_x, 1160 * ascale_y, "FAILURE TO PROPERLY LATCH SEAT AND HEED");
    ege_outtextxy(732 * ascale_x, 1180 * ascale_y, "ALL INSYRUCYIONS CAN RESULY IN BOOILY");
    ege_outtextxy(732 * ascale_x, 1200 * ascale_y, "INJURY OR DEAYH");

    setfont((int)(25 * ascale_x), 0, "Arial Narrow");
    ege_outtextxy(441 * ascale_x, 199 * ascale_y, "MANEUVRING SPEED");
    ege_outtextxy(500 * ascale_x, 224 * ascale_y, "110 KIAS");

    setfont((int)(30 * ascale_x), 0, "Arial Narrow");
    ege_outtextxy(208 * ascale_x, 363 * ascale_y, "WARNING");
    setfont((int)(25 * ascale_x), 0, "Arial Narrow");
    ege_outtextxy(206 * ascale_x, 400 * ascale_y, "ASSURE THAT ALL");
    ege_outtextxy(213 * ascale_x, 420 * ascale_y, "CONTAMINANTS,");
    ege_outtextxy(149 * ascale_x, 440 * ascale_y, "INCLUDING WATER, ARE");
    ege_outtextxy(129 * ascale_x, 460 * ascale_y, "REMOVED FROM FUEL AND");
    ege_outtextxy(115 * ascale_x, 480 * ascale_y, "FUEL SYSTEM BEFORE FLIGHT.");
    ege_outtextxy(92 * ascale_x, 500 * ascale_y, "FAILURE TO ASSURE CONTAMINANT");
    ege_outtextxy(92 * ascale_x, 520 * ascale_y, "FREE FUEL AND HEED ALL SAFETY");
    ege_outtextxy(95 * ascale_x, 540 * ascale_y, "INSTRUCTIONS AND OWNER");
    ege_outtextxy(107 * ascale_x, 560 * ascale_y, "ADVISORIES PRIOR TO FLIGHT");
    ege_outtextxy(121 * ascale_x, 580 * ascale_y, "CAN RESULT IN BODILY INJURY");
    ege_outtextxy(129 * ascale_x, 600 * ascale_y, "OR DEATH.");

    float bigsize = 220 * ascale_x;
    // 大螺丝
    // 中左
    bigshadow(710 * ascale_x, 50 * ascale_y, bigsize);
    bigshadow(710 * ascale_x, 545 * ascale_y, bigsize);
    bigshadow(710 * ascale_x, 1000 * ascale_y, bigsize);
    // 中上
    bigshadow(1340 * ascale_x, 50 * ascale_y, bigsize);
    // 中右
    bigshadow(1964 * ascale_x, 50 * ascale_y, bigsize);
    bigshadow(1964 * ascale_x, 545 * ascale_y, bigsize);
    bigshadow(1964 * ascale_x, 1000 * ascale_y, bigsize);
    // 左
    bigshadow(645 * ascale_x, 60 * ascale_y, bigsize);
    bigshadow(166 * ascale_x, 405 * ascale_y, bigsize);
    // 右
    bigshadow(2028 * ascale_x, 50 * ascale_y, bigsize);
    bigshadow(2500 * ascale_x, 50 * ascale_y, bigsize);
    bigshadow(2500 * ascale_x, 545 * ascale_y, bigsize);
    bigshadow(2500 * ascale_x, 1000 * ascale_y, bigsize);
    // 下
    bigshadow(2500 * ascale_x, 1530 * ascale_y, bigsize);
    bigshadow(1985 * ascale_x, 1530 * ascale_y, bigsize);
    bigshadow(1370 * ascale_x, 1530 * ascale_y, bigsize);
    bigshadow(1298 * ascale_x, 1530 * ascale_y, bigsize);
    bigshadow(807 * ascale_x, 1530 * ascale_y, bigsize);
    bigshadow(291 * ascale_x, 1530 * ascale_y, bigsize);


    // 方向盘的底座

    setfillcolor(EGEARGB(255, 33, 30, 28));
    ege_fillellipse((1336 - 98) * ascale_x, (1123) * ascale_y, 98 * 2 * ascale_x, 98 * 2 * ascale_x);
    setfillcolor(EGEARGB(255, 24, 20, 18));
    ege_fillellipse((1336 - 98 + 13) * ascale_x, (1123 + 13) * ascale_y, (98 - 13) * 2 * ascale_x, (98 - 13) * 2 * ascale_x);
    smallscrew(1336 * ascale_x, 1221 * ascale_y, 150 * ascale_x);
}

void bigshadow(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS)
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)DIAL_RADIUS;
    const float CENTER_X_F = (float)CENTER_X;
    const float CENTER_Y_F = (float)CENTER_Y;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
              roundf(cx - SCREW_OFFSET * 0.5f),
                roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(140, 140, 140)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(50, 50, 50))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1 / 2), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1 / 2), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy - CROSS_OFFSET2;
        const float cross_y_end = cy - CROSS_OFFSET2 * 3.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F,
        CENTER_Y_F + RECT_WIDTH / 9.4
    );

    setlinewidth(LINE_WIDTH / 0.95);
    setcolor(EGERGB(140, 140, 140));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 7.5);
    setlinewidth(LINE_WIDTH / 1.8);
    setcolor(EGERGB(30, 30, 30));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 7.5);
    setlinewidth(LINE_WIDTH / 1.8);
    setcolor(EGERGB(30, 30, 30));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 5);
}

void smallscrew(float CENTER_X, float CENTER_Y, float DIAL_RADIUS)//螺丝
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)DIAL_RADIUS;
    const float CENTER_X_F = (float)CENTER_X;
    const float CENTER_Y_F = (float)CENTER_Y;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
                    roundf(cx - SCREW_OFFSET * 0.5f),
                    roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(170, 170, 170)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(20, 20, 20))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy + CROSS_OFFSET2 / 4;
        const float cross_y_end = cy - CROSS_OFFSET2 * 4.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F - screw_radius * 0.65,
        CENTER_Y_F - DIAL_RADIUS_F * 0.65
    );

    // 右上
    draw_screw(
        CENTER_X_F + screw_radius * 0.65,
        CENTER_Y_F - DIAL_RADIUS_F * 0.65
    );

    // 右下
    draw_screw(
        CENTER_X_F + screw_radius * 0.65,
        CENTER_Y_F + DIAL_RADIUS_F * 0.65
    );

    // 左下（新增）
    draw_screw(
        CENTER_X_F - screw_radius * 0.65,
        CENTER_Y_F + DIAL_RADIUS_F * 0.65
    );
}

// 控制盘的绘制
void shadowHomepage(float CENTER_X, float CENTER_Y, float DIAL_RADIUS)
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)DIAL_RADIUS;
    const float CENTER_X_F = (float)CENTER_X;
    const float CENTER_Y_F = (float)CENTER_Y;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
              roundf(cx - SCREW_OFFSET * 0.5f),
                roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(140, 140, 140)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(50, 50, 50))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1 / 2), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1 / 2), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy - CROSS_OFFSET2;
        const float cross_y_end = cy - CROSS_OFFSET2 * 3.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F,
        CENTER_Y_F + RECT_WIDTH / 9.4
    );

    setlinewidth(LINE_WIDTH / 0.95);
    setcolor(EGERGB(140, 140, 140));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 7.5);
    setlinewidth(LINE_WIDTH / 1.8);
    setcolor(EGERGB(30, 30, 30));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 7.5);
    setlinewidth(LINE_WIDTH / 1.8);
    setcolor(EGERGB(30, 30, 30));
    ege_circle(CENTER_X_F,
        CENTER_Y_F, RECT_WIDTH / 5);
}

void bkshapeHomepage(float x, float y, float h)
{
    const float width = h * 5.4789f; // 1041/190
    const float round_rect_width = width - 1;
    const float round_rect_height = h - 2;
    const float round_radius = h * 0.0526f; // 10/190

    ege_enable_aa(TRUE);  // 启用抗锯齿

    setfillcolor(EGERGB(32, 32, 32));
    ege_fillrect(x, y, width, h);

    setcolor(EGERGB(50, 50, 50));
    setlinewidth(h * 0.0421f); // 8/190
    ege_roundrect(x + 1, y + 1, round_rect_width, round_rect_height, round_radius);

    setcolor(EGERGB(19, 19, 19));
    setlinewidth(h * 0.0316f); // 6/190
    ege_roundrect(x, y, width, h, round_radius);
}

void numberHomepage(float x, float y, float h)
{
    const float text_y1 = y + h * 0.1f;  // 306-287=19, 19/190≈0.1
    const float text_y2 = y + h * 0.2316f; // 331-287=44, 44/190≈0.2316
    const float text_y3 = y + h * 0.5263f; // 387-287=100, 100/190≈0.5263
    const float text_x_start = x + h * 61 / 190; // 147-86=61, 61/190≈0.3211
    const float button_spacing = h * 112 / 190; // 112/190≈0.5895
    settextjustify(LEFT_TEXT, TOP_TEXT);
    ege_enable_aa(TRUE);  // 启用抗锯齿
    setcolor(EGERGB(170, 170, 170));
    setfont(h * 0.1053f, h * 0.0737f, "楷体"); // 20/190≈0.1053, 14/190≈0.0737
    setbkmode(TRANSPARENT);//去除文字背景色

    outtextxy(x + h * (147 - 86) / 190, text_y1, "AVN");
    outtextxy(x + h * (147 - 86) / 190, text_y2, "FAN");
    outtextxy(x + h * 0.8474f, text_y1, "AUTO");
    outtextxy(x + h * 0.8474f, text_y2, "PILOT");
    outtextxy(x + h * 1.4579f, text_y2, "GPS");
    outtextxy(x + h * 2.0f, text_y1, "NAV");
    outtextxy(x + h * 1.9526f, text_y2, "COM1");
    outtextxy(x + h * 2.5947f, text_y1, "NAV");
    outtextxy(x + h * 2.5263f, text_y2, "COM2");
    outtextxy(x + h * 3.2105f, text_y2, "ADF");
    outtextxy(x + h * 3.7737f, text_y2, "XPNDR");
    outtextxy(x + h * 4.4053f, text_y2, "DME");

    setcolor(EGERGB(25, 25, 25));
    setfont(h * 0.2105f, h * 0.1263f, "MS UI Gothic"); // 40/190≈0.2105, 24/190≈0.1263
    setbkmode(TRANSPARENT);//去除文字背景色

    float button_x = x + h * 55 / 190; // 153-86=67, 67/190≈0.3526
    outtextxy(button_x, text_y3, "5");
    outtextxy(button_x + button_spacing, text_y3, "5");
    outtextxy(button_x + button_spacing * 2, text_y3, "5");
    outtextxy(button_x + button_spacing * 3 - h * 0.0632f, text_y3, "1"); // 12/190≈0.0632

    outtextxy(button_x + button_spacing * 4 - h * 0.0632f, text_y3, "1");

    outtextxy(button_x + button_spacing * 5, text_y3, "5");
    outtextxy(button_x + button_spacing * 6, text_y3, "5");
    outtextxy(button_x + button_spacing * 7, text_y3, "5");

    setfont(h * 0.2105f, h * 0.1053f, "MS UI Gothic"); // 40/190≈0.2105, 20/190≈0.1053
    outtextxy(button_x + button_spacing * 3 + h * 0.0632f, text_y3, "0");
    outtextxy(button_x + button_spacing * 4 + h * 0.0632f, text_y3, "0");
}

void buttonHomepage(float x, float y, float h, float button_x)
{
    const float button_center_y = y + h * 112 / 190; // 399-287=112, 112/190≈0.5895
    const float button_radius1 = h * 39 / 190; // 39/190≈0.2053
    const float button_radius2 = h * 32 / 190; // 32/190≈0.1684
    const float button_radius3 = h * 27 / 190; // 27/190≈0.1421

    ege_enable_aa(TRUE);  // 启用抗锯齿
    setfillcolor(EGERGB(11, 11, 11));
    ege_fillcircle(button_x + h * 0.0526f, button_center_y, button_radius1);

    setfillcolor(EGERGB(48, 44, 42));
    ege_fillcircle(button_x + h * 0.0263f, button_center_y + h * 0.0105f, button_radius2);
    setfillcolor(EGERGB(96, 96, 96));
    ege_fillcircle(button_x, button_center_y + h * 0.0211f, button_radius3);

    setlinewidth(h * 0.0263f); // 5/190≈0.0263
    setcolor(EGERGB(45, 45, 45));
    ege_circle(button_x, button_center_y + h * 0.0211f, button_radius3);

    setlinewidth(h * 0.0053f); // 1/190≈0.0053
    setcolor(EGERGB(19, 19, 19));
    ege_circle(button_x, button_center_y + h * 0.0211f, button_radius3 + h * 0.0053f);
}

void drawPanle(float x, float y, float h) {


    //initgraph(1500, 600);
    //setbkcolor(EGERGB(76, 76, 76));

    bkshapeHomepage(x, y, h);

    float button_x = x + h * 67 / 190; // 153-86=67, 67/190≈0.3526
    const float button_spacing = h * 112 / 190; // 112/190≈0.5895
    for (int i = 0; i < 8; i++) {
        buttonHomepage(x, y, h, button_x + button_spacing * i);
    }

    const float dial_radius = h * 0.6316f; // 120/190≈0.6316
    shadowHomepage(x + h * 0.1158f, y + h * 0.1263f, dial_radius); // 108-86=22, 22/190≈0.1158; 311-287=24, 24/190≈0.1263
    shadowHomepage(x + h * 0.1158f, y + h * 0.9053f, dial_radius); // 459-287=172, 172/190≈0.9053
    shadowHomepage(x + h * 1.8158f, y + h * 0.1263f, dial_radius); // 431-86=345, 345/190≈1.8158
    shadowHomepage(x + h * 1.8158f, y + h * 0.9053f, dial_radius);
    shadowHomepage(x + h * 4.1789f, y + h * 0.1263f, dial_radius); // 880-86=794, 794/190≈4.1789
    shadowHomepage(x + h * 4.1789f, y + h * 0.9053f, dial_radius);
    shadowHomepage(x + h * 5.3474f, y + h * 0.1263f, dial_radius); // 1102-86=1016, 1016/190≈5.3474
    shadowHomepage(x + h * 5.3474f, y + h * 0.9053f, dial_radius);

    numberHomepage(x, y, h);
    //getch();

    //closegraph();
    //return 0;
}
//void drawHomePage()
//{
//    int height, width;
//    setcaption("N172SP");
//    //    int scrWidth = GetSystemMetrics(SM_CXSCREEN);
//    //    int scrHeight = GetSystemMetrics(SM_CYSCREEN);
//
//        // 初始化全屏窗口（无边框模式）
//    initgraph(-1, -1, INIT_NOFORCEEXIT | INIT_NOBORDER);
//    const char* IP = "127.0.0.1";      //IP Address of computer running X-Plane
//    XPCSocket sock = openUDP(IP);
//
//    height = getheight();
//    width = getwidth();
//
//    float ascale_x = width / 2560.0;  // X 方向缩放因子
//    float ascale_y = height / 1600.0; // Y 方向缩放因子
//
//    //setbkcolor(BLACK);
//    ege_enable_aa(true);
//
//    float x0 = 17 * ascale_x;
//    float y0 = 11 * ascale_y;
//    //setlinecolor(BLACK);
//    //setfillcolor(EGEARGB(255, 105, 103, 101));
//    //ege_fillroundrect(x0, y0, 2520 * ascale_x, 1562 * ascale_y, 689 * ascale_x, 0, 0, 0);
//    //setlinewidth(3 * ascale_x);
//    //setlinecolor(EGEARGB(255, 29, 26, 25));
//    //ege_roundrect(694 * ascale_x, 0 * ascale_y, 1287 * ascale_x, 1024 * ascale_y, 0, 0, 10 * ascale_x, 10 * ascale_x);
//    //ege_line(1336 * ascale_x, 1024 * ascale_y, 1336 * ascale_x, height);
//
//    float pitch = 0;
//    float roll = 0;
//    double current_heading = 0;
//    int size = 1;
//
//    for (; is_run(); delay_fps(60), pitch += M_PI / 100, roll += M_PI / 100) {
//        cleardevice();
//        // 背景
//
//        setlinecolor(BLACK);
//        setfillcolor(EGEARGB(255, 105, 103, 101));
//        ege_fillroundrect(x0, y0, 2520 * ascale_x, 1562 * ascale_y, 689 * ascale_x, 0, 0, 0);
//        setlinewidth(3 * ascale_x);
//        setlinecolor(EGEARGB(255, 29, 26, 25));
//        ege_roundrect(694 * ascale_x, 0 * ascale_y, 1287 * ascale_x, 1024 * ascale_y, 0, 0, 10 * ascale_x, 10 * ascale_x);
//        ege_line(1336 * ascale_x, 1024 * ascale_y, 1336 * ascale_x, height);
//        // 标签
//        setfillcolor(EGEARGB(255, 36, 34, 30));
//        setlinecolor(EGEARGB(255, 0, 0, 0));
//        ege_roundrect(951 * ascale_x, 40 * ascale_y, 190 * ascale_x, 75 * ascale_y, 10 * ascale_x);
//        ege_fillroundrect(951 * ascale_x, 40 * ascale_y, 190 * ascale_x, 75 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 20, 19, 17));
//        ege_roundrect(962 * ascale_x, 50 * ascale_y, 168 * ascale_x, 55 * ascale_y, 10 * ascale_x);
//
//        ege_fillroundrect(962 * ascale_x, 50 * ascale_y, 168 * ascale_x, 55 * ascale_y, 10 * ascale_x);
//        setbkmode(TRANSPARENT);
//        settextjustify(CENTER_TEXT, CENTER_TEXT);
//        setcolor(WHITE);
//        setfont((int)(50 * ascale_x), 0, "Arial Narrow");
//        ege_outtextxy(1045 * ascale_x, 55 * ascale_y, "N172SP");
//
//        // 标签右边的
//        setcolor(BLACK);
//        ege_roundrect(1458 * ascale_x, 40 * ascale_y, 327 * ascale_x, 77 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 22, 20, 19));
//        ege_fillroundrect(1458 * ascale_x, 40 * ascale_y, 327 * ascale_x, 77 * ascale_y, 10 * ascale_x);
//        ege_roundrect(1468 * ascale_x, 50 * ascale_y, 307 * ascale_x, 55 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 18, 17, 15));
//        ege_fillroundrect(1468 * ascale_x, 50 * ascale_y, 307 * ascale_x, 55 * ascale_y, 10 * ascale_x);
//        setbkmode(TRANSPARENT);
//        setfont((int)(30 * ascale_x), 0, "Arial Narrow");
//        //        setcolor(EGEARGB(255, 36, 31, 27));
//        setcolor(EGEARGB(255, 191, 175, 102));
//        settextjustify(LEFT_TEXT, TOP_TEXT);
//        ege_outtextxy(1475 * ascale_x, 52 * ascale_y, "L FUEL R");
//        setcolor(EGEARGB(255, 176, 43, 31));
//        ege_outtextxy(1475 * ascale_x, 78 * ascale_y, "QIL PRESS");
//        setcolor(EGEARGB(255, 128, 117, 58));
//        ege_outtextxy(1605 * ascale_x, 78 * ascale_y, "L VAC R");
//        setcolor(EGEARGB(255, 176, 43, 31));
//        ege_outtextxy(1701 * ascale_x, 78 * ascale_y, "VOLTS");
//
//        // NAV GPS 如果可以点击更好
//        setlinecolor(EGEARGB(255, 0, 0, 0));
//        ege_roundrect(2110 * ascale_x, 40 * ascale_y, 155 * ascale_x, 77 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 22, 20, 19));
//        ege_fillroundrect(2110 * ascale_x, 40 * ascale_y, 155 * ascale_x, 77 * ascale_y, 10 * ascale_x);
//        ege_roundrect(2120 * ascale_x, 50 * ascale_y, 135 * ascale_x, 57 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 18, 17, 15));
//        ege_fillroundrect(2120 * ascale_x, 50 * ascale_y, 135 * ascale_x, 57 * ascale_y, 10 * ascale_x);
//        setcolor(EGEARGB(255, 184, 175, 80));
//        ege_outtextxy(2133 * ascale_x, 52 * ascale_y, "NAV");
//        setcolor(EGEARGB(255, 35, 175, 134));
//        ege_outtextxy(2133 * ascale_x, 80 * ascale_y, "GPS");
//
//        setlinecolor(EGEARGB(255, 255, 255, 255));
//        ege_roundrect(2197 * ascale_x, 55 * ascale_y, 47 * ascale_x, 47 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 21, 21, 22));
//        ege_fillroundrect(2197 * ascale_x, 55 * ascale_y, 47 * ascale_x, 47 * ascale_y, 10 * ascale_x);
//        setcolor(EGEARGB(255, 255, 255, 255));
//        setfont((int)(23 * ascale_x), 0, "Arial Narrow");
//        ege_outtextxy(2205 * ascale_x, 60 * ascale_y, "NAV");
//        ege_outtextxy(2205 * ascale_x, 78 * ascale_y, "GPS");
//
//        // 左下角的板子
//        setlinecolor(EGEARGB(255, 0, 0, 0));
//        ege_roundrect(86 * ascale_x, 1300 * ascale_y, 1047 * ascale_x, 191 * ascale_y, 10 * ascale_x);
//        setfillcolor(EGEARGB(255, 21, 21, 22));
//        ege_fillroundrect(86 * ascale_x, 1300 * ascale_y, 1047 * ascale_x, 191 * ascale_y, 10 * ascale_x);
//
//
//
//
//        // 一些文字的显示
//        setbkmode(TRANSPARENT);
//        setfont((int)(30 * ascale_x), 0, "Arial Narrow");
//        setcolor(EGEARGB(255, 200, 200, 200));
//        ege_outtextxy(860 * ascale_x, 1079 * ascale_y, "WARNING");
//        setfont((int)(25 * ascale_x), 0, "Arial Narrow");
//        settextjustify(LEFT_TEXT, TOP_TEXT);
//        ege_outtextxy(732 * ascale_x, 1120 * ascale_y, "ASSUME THAT SEAT IS LOCKED IN POSITION");
//        ege_outtextxy(732 * ascale_x, 1140 * ascale_y, "PRIOR TO TAXI. TAKE-OFF, AND LANDING.");
//        ege_outtextxy(732 * ascale_x, 1160 * ascale_y, "FAILURE TO PROPERLY LATCH SEAT AND HEED");
//        ege_outtextxy(732 * ascale_x, 1180 * ascale_y, "ALL INSYRUCYIONS CAN RESULY IN BOOILY");
//        ege_outtextxy(732 * ascale_x, 1200 * ascale_y, "INJURY OR DEAYH");
//
//        setfont((int)(25 * ascale_x), 0, "Arial Narrow");
//        ege_outtextxy(441 * ascale_x, 199 * ascale_y, "MANEUVRING SPEED");
//        ege_outtextxy(500 * ascale_x, 224 * ascale_y, "110 KIAS");
//
//        setfont((int)(30 * ascale_x), 0, "Arial Narrow");
//        ege_outtextxy(208 * ascale_x, 363 * ascale_y, "WARNING");
//        setfont((int)(25 * ascale_x), 0, "Arial Narrow");
//        ege_outtextxy(206 * ascale_x, 400 * ascale_y, "ASSURE THAT ALL");
//        ege_outtextxy(213 * ascale_x, 420 * ascale_y, "CONTAMINANTS,");
//        ege_outtextxy(149 * ascale_x, 440 * ascale_y, "INCLUDING WATER, ARE");
//        ege_outtextxy(129 * ascale_x, 460 * ascale_y, "REMOVED FROM FUEL AND");
//        ege_outtextxy(115 * ascale_x, 480 * ascale_y, "FUEL SYSTEM BEFORE FLIGHT.");
//        ege_outtextxy(92 * ascale_x, 500 * ascale_y, "FAILURE TO ASSURE CONTAMINANT");
//        ege_outtextxy(92 * ascale_x, 520 * ascale_y, "FREE FUEL AND HEED ALL SAFETY");
//        ege_outtextxy(95 * ascale_x, 540 * ascale_y, "INSTRUCTIONS AND OWNER");
//        ege_outtextxy(107 * ascale_x, 560 * ascale_y, "ADVISORIES PRIOR TO FLIGHT");
//        ege_outtextxy(121 * ascale_x, 580 * ascale_y, "CAN RESULT IN BODILY INJURY");
//        ege_outtextxy(129 * ascale_x, 600 * ascale_y, "OR DEATH.");
//
//
//        // 方向盘的底座
//        setfillcolor(EGEARGB(255, 33, 30, 28));
//        ege_fillellipse((1336 - 98) * ascale_x, (1123) * ascale_y, 98 * 2 * ascale_x, 98 * 2 * ascale_x);
//        setfillcolor(EGEARGB(255, 24, 20, 18));
//        ege_fillellipse((1336 - 98 + 13) * ascale_x, (1123 + 13) * ascale_y, (98 - 13) * 2 * ascale_x, (98 - 13) * 2 * ascale_x);
//
//        // 数据传输
//
//        //getDREF(sock, "sim/flightmodel/position/theta", &pitch, &size);
//        //getDREF(sock, "sim/flightmodel/position/phi", &roll, &size);
//
//        //pitch = ( - pitch) * M_PI / 180;
//        //roll =  (- roll)* M_PI / 180;
//
//        // 六个表盘
//        drawAttitudeIndicator(1343 * ascale_x, 328 * ascale_y, 231 * ascale_x, pitch, roll);
//        setfillcolor(EGEARGB(255, 168, 255, 128));
//        ege_fillellipse((915 - 195) * ascale_x, (332 - 195) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        //ege_fillellipse((1764 - 195) * ascale_x, (332 - 196) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((1343 - 195) * ascale_x, (591) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((915 - 195) * ascale_x, (591) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((1764 - 195) * ascale_x, (591) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        drawHI(1343 * ascale_x, 786 * ascale_y, 173 * ascale_x, roll * 50);
//        drawTC(915 * ascale_x, 786 * ascale_y, 171 * ascale_x);
//        drawAI(915 * ascale_x, 332 * ascale_y, 171 * ascale_x, roll * 50);
//        drawAM(1764 * ascale_x, 332 * ascale_y, 163 * ascale_x, roll * 50);
//        drawVS(1764 * ascale_x, 786 * ascale_y, 171 * ascale_x, roll * 50);
//
//        // 外面表盘
//        // 右
//        setfillcolor(EGEARGB(255, 168, 255, 128));
//        ege_fillellipse((2223 - 195) * ascale_x, (332 - 195) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((2223 - 195) * ascale_x, (788 - 195) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((2223 - 195) * ascale_x, (1248 - 195) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        ege_fillellipse((1763 - 195) * ascale_x, (1248 - 195) * ascale_y, 195 * 2 * ascale_x, 195 * 2 * ascale_x);
//        drawCDI(2223 * ascale_x, 332 * ascale_y, 175 * ascale_x, 0);
//        drawGSI(2223 * ascale_x, 788 * ascale_y, 175 * ascale_x, 0);
//        drawADF(2223 * ascale_x, 1248 * ascale_y, 175 * ascale_x, 0);
//
//
//        // 左
//        setfillcolor(EGEARGB(255, 168, 255, 128));
//        ege_fillellipse((533 - 131) * ascale_x, (786 - 131) * ascale_y, 131 * 2 * ascale_x, 131 * 2 * ascale_x);
//        ege_fillellipse((232 - 131) * ascale_x, (786 - 131) * ascale_y, 131 * 2 * ascale_x, 131 * 2 * ascale_x);
//        ege_fillellipse((232 - 131) * ascale_x, (1101 - 131) * ascale_y, 131 * 2 * ascale_x, 131 * 2 * ascale_x);
//        ege_fillellipse((533 - 131) * ascale_x, (1101 - 131) * ascale_y, 131 * 2 * ascale_x, 131 * 2 * ascale_x);
//        drawFQI(232 * ascale_x, 786 * ascale_y, 111 * ascale_x);
//        drawFFI(533 * ascale_x, 786 * ascale_y, 111 * ascale_x);
//        drawVGA(533 * ascale_x, 1101 * ascale_y, 120 * ascale_x);
//        drawOTP(232 * ascale_x, 1101 * ascale_y, 120 * ascale_x);
//        // 时间表
//        setfillcolor(EGEARGB(255, 168, 255, 128));
//        ege_fillellipse((533 - 135) * ascale_x, (416 - 135) * ascale_y, 135 * 2 * ascale_x, 135 * 2 * ascale_x);
//        drawDCO(122 * ascale_x, 533 * ascale_x, 416 * ascale_y);
//    }
//    getch();
//    closegraph();
//}